package com.xyh.transaction.common;

import java.util.HashMap;
import java.util.Map;

public enum GoodsCondition {
    BRAND_NEW("全新"),
    LIKE_NEW("几乎全新"),
    VERY_GOOD("非常好"),
    GOOD("好"),
    ACCEPTABLE("可接受");

    private static final Map<String, GoodsCondition> map = new HashMap<>();

    static {
        for (GoodsCondition condition : GoodsCondition.values()) {
            map.put(condition.getDetail(), condition);
        }
    }

    private final String detail;

    GoodsCondition(String detail) {
        this.detail = detail;
    }

    public String getDetail() {
        return detail;
    }

    public static GoodsCondition getByDetail(String detail) {
        GoodsCondition condition = map.get(detail);
        if (condition == null) {
            throw new IllegalArgumentException("错误的商品成色: " + detail);
        }
        return condition;
    }

}
